package leetcode;

//给定两个二叉树，编写一个函数来检验它们是否相同。
//如果两个树在结构上相同，并且节点具有相同的值，则认为它们是相同的。
public class problems_100 {

    public static void main(String[] arge) {
        TreeNode A1 = new TreeNode(1);
        TreeNode A2 = new TreeNode(2);
        TreeNode A3 = new TreeNode(3);
        A1.left = A2;
        A1.right = A3;
        TreeNode B1 = new TreeNode(1);
        TreeNode B2 = new TreeNode(2);
        TreeNode B3 = new TreeNode(3);
        B1.left = B2;
//        B1.right = B3;
        boolean ret = new Solution().isSameTree(A1, B1);
        System.out.println(ret);
    }
    static class Solution {
        public boolean isSameTree(TreeNode p, TreeNode q) {
            return checkNode(p, q);
        }
        private boolean checkNode(TreeNode p, TreeNode q){
            if(null == p && null == q) return true;
            if(null == p || null == q) return false;
            if(p.val != q.val) return false;
            return checkNode(p.left, q.left) && checkNode(p.right, q.right);
        }
    }
    public static class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;
        TreeNode(int x) { val = x; }
    }
}
